<template>
<div>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(carousel,index) in list" :key="carousel.id">
        <img :src="carousel.imgUrl"/>
      </div>
    </div>
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
  </div>
</div>
</template>

<script>
import Swiper from "swiper";
export default {
  name: "Carousel",
  props:['list'],
  watch:{
    list: {
      handler(newValue, oldValue) {
        this.$nextTick(() => {//有时可以直接放在mounted里面(当里面的数据非常少，请求速度快时(可能显示不清),或者是在父组件中已经请求到了数据
          //直接传递来的值 )
          let mySwiper = new Swiper('.swiper-container', {
            //direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项
            autoplay: true,//设置自动轮播
            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination'
            },
            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
          })
          // mySwiper.el.onmouseover = function(){ //鼠标放上暂停轮播(这里暂时用不了,使用swiper7或者不封装组件)
          //   mySwiper.autoplay.stop();
          // }
          // mySwiper.el.onmouseleave = function(){
          //   mySwiper.autoplay.start();
          // }
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
